module.exports = function ($scope, $resource, $modal, toaster) {

	//查询实时机构补贴金额
	$scope.search = function() {
		$scope.searchform.loading = true;
		var para = {
			'company_code': $scope.searchform.code
		}
		$resource('/api/ac/atc/companyService/getSubsidyUseList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.subsidy_list = res.data;
				var exp = '';
				angular.forEach($scope.subsidy_list, function(item) {
					if(item.subsidy_one){
						exp = item.subsidy_one.replace('1_', item.domestic_one + '*');
						exp = exp.replace('2_', item.foreigner_one + '*');
					}
					if(item.subsidy_more){
						exp += '+' + item.subsidy_more.replace('1_', item.domestic_more + '*');
						exp = exp.replace('2_', item.foreigner_more + '*');
					}

					if(exp){
						item.money = eval(exp);
					} else {
						item.money = 0;
					}
				});
            } else {
                toaster.error({title: '', body: '查询信息失败'});
			}
			$scope.searchform.loading = false;
        });
	}

	//加载参加招徕奖励活动的机构名单
	$scope.loadCompany = function() {
		$resource('/api/as/atc/tourist/companySimList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
				$scope.searchform.company_list = res.data;
				$scope.searchform.company_list.unshift({'company_name': '全部', 'company_code': undefined});
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

	init();
	function init(){
		$scope.searchform = {};
		$scope.search();
		$scope.loadCompany();
		$resource('/api/ac/atc/policyService/getPublishPolicy', {}, {}).save({'balance': '1'}, function(res){
			if (res.errcode === 0) {
				$scope.policy = res.data;
				var exp;
				angular.forEach($scope.policy.useing, function(item) {
					exp = item.subsidy_one || '';
					if(item.subsidy_more){
						exp += '+' + item.subsidy_more;
					}
					if(exp){
						$scope.policy.use_subsidy += eval(exp);
					}
				});
            } else {
                toaster.error({title: '', body: '查询信息失败'});
            }
        });
	}

	//明细
	$scope.getInfo = function(item) {
		var modalInstance = $modal.open({
			template: require('../views/groupDetail.html'),
			controller: 'groupDetail',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				}
			}
		});
	}

};